﻿namespace WMS6.Web.Billing
{
    using System;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.BillingServiceRef;

    public class StatementDetail : BasePage
    {
        protected Button btnCancel;
        protected Button btnSave;
        protected HtmlForm F9203;
        protected HtmlInputHidden hdnFlag;
        protected HtmlInputHidden hdnFrom;
        protected HtmlInputHidden hdnStatementID;
        protected HtmlHead Head1;
        protected Label lblAreaDetail;
        protected Label lblLineID;
        protected Label lblMsg;
        protected Label lblOrderID;
        protected Label lblQty;
        protected Label lblReceivable;
        protected Label lblReceived;
        protected Label lblRemark;
        protected Label lblSkuID;
        protected Label lblSourceType;
        protected Label lblType;
        protected HtmlLink mycss;
        protected Label one1;
        protected ScriptManager ScriptManager1;
        protected TextBox txtLineID;
        protected TextBox txtOrderID;
        protected TextBox txtQty;
        protected TextBox txtReceivable;
        protected TextBox txtReceived;
        protected TextBox txtRemark;
        protected TextBox txtSkuID;
        protected TextBox txtSourceType;
        protected TextBox txtType;

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            base.Server.Transfer(string.Format("Statement.aspx?from={0}&detail={1}&ID={2}", base.UrlEncode(this.hdnFrom.Value), "1", base.UrlEncode(this.hdnStatementID.Value)));
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtReceived.Text.Trim()))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F9200_010");
            }
            else
            {
                try
                {
                    StatementDetailInfo statementDetailInfo = base.DataEntityViewState as StatementDetailInfo;
                    statementDetailInfo.Received = decimal.Parse(this.txtReceived.Text);
                    statementDetailInfo.Remark = this.txtRemark.Text;
                    statementDetailInfo.UpdatedBy = base.UserInfo.UserID;
                    this.lblMsg.Text = BillingServiceClientProxy.GetInstance().UpdateStatementDetailReceived(statementDetailInfo) + base.GetGlobalMsgResource("F9200_007");
                    this.hdnFlag.Value = "1";
                    base.Server.Transfer(string.Format("Statement.aspx?from={0}&detail={1}&ID={2}", base.UrlEncode(this.hdnFrom.Value), "1", base.UrlEncode(this.hdnStatementID.Value)));
                }
                catch (Exception ex)
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("F9200_011") + ex.Message;
                }
            }
        }

        private void LoadData()
        {
            if (!string.IsNullOrEmpty(base.Request.QueryString["from"]))
            {
                string from = base.Request.QueryString["from"];
                this.hdnFrom.Value = from;
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["ID"]))
            {
                this.hdnStatementID.Value = base.Request.QueryString["ID"];
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["LineID"]))
            {
                this.txtLineID.Text = base.Request.QueryString["LineID"];
            }
            this.SetTextBoxByStatementDetailInfo();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
            }
        }

        private void SetTextBoxByStatementDetailInfo()
        {
            try
            {
                StatementDetailInfo statementDetailInfo = BillingServiceClientProxy.GetInstance().GetStatementDetailInfoByID(this.hdnStatementID.Value, this.txtLineID.Text);
                if (statementDetailInfo != null)
                {
                    this.txtLineID.Text = statementDetailInfo.LineID.ToString();
                    this.txtOrderID.Text = statementDetailInfo.OrderID;
                    this.txtReceivable.Text = base.GetPreferenceDigit(statementDetailInfo.Receivable);
                    this.txtReceived.Text = base.GetPreferenceDigit(statementDetailInfo.Received);
                    this.txtRemark.Text = statementDetailInfo.Remark;
                    this.txtQty.Text = base.GetPreferenceDigit(statementDetailInfo.Qty);
                    this.txtSkuID.Text = statementDetailInfo.SkuID;
                    this.txtType.Text = statementDetailInfo.Type;
                    this.txtSourceType.Text = statementDetailInfo.SourceType;
                    base.DataEntityViewState = statementDetailInfo;
                }
                else
                {
                    this.lblMsg.Text = this.hdnStatementID.Value + base.GetGlobalMsgResource("F9200_009");
                    this.lblMsg.Visible = true;
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
                this.lblMsg.Visible = true;
            }
        }
    }
}

